const fs=require('fs');
const path=require('path');
const url=require('url');
const http=require('http');

http.createServer((req, res) => {
    // console.log(url.parse(req.url,true));
    let {pathname}=url.parse(req.url ,true);
    console.log(pathname);
    pathname=pathname=='/'?'index.html':pathname;
    if(path.extname(pathname)&&path.extname(pathname)!=='.ico'){
        res.end(fs.readFileSync(path.join('./public', pathname),'utf-8'))
    }
    res.end('hello')
}).listen(8082,  (err) => {
    console.log('服务器启动成功,http://localhost:8082')
})